﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SMSSnew.smss_web_reference;
using SMSSnew.CLASSES;

namespace SMSSnew.DATA
{

    public class SpecialMedicalDA
    {
        static smss_web_service_app srv = new smss_web_service_app();
        static readXML XMLreader = new readXML();

        static DataTable leaveTable = new DataTable();

        public string validateSpecialMedDurationHasEarlyRequests(DateTime FromDate, DateTime ToDate, string teacher_id)
        {
            string message = "";
            string query = "";
            try
            {
                for (DateTime i = FromDate; i <= ToDate; i = i.AddDays(1))
                {
                    query = XMLreader.readXMLtxt("checkLeaveRequestedEarlier", "~/DATA/XML/LeaveXML.xml");
                    query = query.Replace("@REQUESTING_DATE", i.ToString("yyyy/M/d"));
                    query = query.Replace("@TEACHER_ID", teacher_id);
                    leaveTable = srv.Search(query);

                    if (leaveTable.Rows.Count > 0)
                    {
                        message = "Sorry! Requesting Duration contains already requested dates. If you need to continue please delete leave " + leaveTable.Rows[0][0].ToString() + " and try again.";
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return message;
        }
    }
}
